<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>我发布的活动</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <div class="layui-tab-item layui-show">
                <div class="layui-tab layui-tab-brief" lay-filter="type">
                    <ul class="layui-tab-title" id="zc_tab">
                        <li <c:if test="${input.timeStatus ==0}">class="layui-this"</c:if>>进行中</li>
                        <li <c:if test="${input.timeStatus == 1}">class="layui-this"</c:if>>已截止</li>
                    </ul>
                    <div class="layui-tab-content">
                        <form class="layui-form" action="${ctx}/activity/activity/activityList.do" id="myForm"
                              method="post">
                            <input type="hidden" name="pageNo" id="pageNo"/>
                            <input type="hidden" name="timeStatus" id="status" value="${input.timeStatus}"/>
                            <div class="f-search-bar">
                                <div class="search-container">
                                    <ul class="search-form-content">
                                        <li class="form-item-inline"><label class="search-form-lable">活动标题</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="title" autocomplete="off" class="layui-input"
                                                       value="${activity.title}"
                                                       placeholder="请输入查询活动标题"
                                                >
                                            </div>
                                        </li>
                                        <c:if test="${!isChild || isXzgsAdmin}">
                                            <li class="form-item-inline"><label class="search-form-lable">发布者</label>
                                                <div class="layui-input-inline">
                                                    <select name="member">
                                                        <option value="">全部</option>
                                                        <c:forEach var="memberGroup" items="${memberGroupList}">
                                                            <option value="${memberGroup.id}" ${memberGroup.id == activity.member ? 'selected="selected"' : ''}>${memberGroup.realname}</option>
                                                        </c:forEach>
                                                    </select>
                                                </div>
                                            </li>
                                        </c:if>
                                        <li class="form-item-inline">
                                            <div class="sub-btns">
                                                <a class="layui-btn layui-btn-danger"
                                                   href="javascript:submitFunction('#myForm')">查询</a>
                                                <a class="layui-btn layui-btn-normal"
                                                   href="javascript:resetFunction('#myForm')">重置</a>
                                            </div>
                                        </li>
                                    </ul>
                                    <ul class="search-form-content">
                                        <li class="form-item"><label class="search-form-lable">发布时间</label>
                                            <div class="check-btn-inner" id="timeType">
                                                <a id="all" href="javascript:void(0);"
                                                   onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                                <input type="hidden" name="timeType" value="${input.timeType}"/>
                                            </div>
                                            <div class="layui-inline">
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" type="text" name="createStart"
                                                           value="${input.createStart}" placeholder="开始日">
                                                </div>
                                                -
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" type="text" name="createEnd"
                                                           value="${input.createEnd}" placeholder="截止日">
                                                </div>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </form>
                        <div class="c-time-list-content">
                            <ul id="view">
                                <c:if test="${page.totalCount == 0}">
                                    <div class="f16 tc mt15">${isTwoLevelChildren ? '还没有数据': '还没有数据，请点击右上角的“发布活动”，发布和编辑内容'}</div>
                                </c:if>
                                <c:forEach var="activity" items="${activities}">
                                    <li>
                                        <div class="detail-content">
                                            <a href="${ctx}/activity/activity/activityDetail.do?actId=${activity.id}"
                                               class="act-logo common-img">
                                                <img src="<c:if test="${ activity.pic!= null}">${activity.pic}?imageMogr2/auto-orient/crop/200x150</c:if>"
                                                     alt=""
                                                     onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                            </a>
                                            <div class="detail">
                                                <div class="act-title">
                                                    <c:choose>
                                                        <c:when test="${activity.checkStatus == 0}">
                                                            <span class="status f18 red">审核中</span>
                                                        </c:when>
                                                        <c:when test="${activity.checkStatus == 1}">
                                                            <c:set var="nowDate" value="<%=new Date()%>"></c:set>
                                                            <c:if test="${activity.endTime > nowDate}">
                                                                <span class="status f18 red">进行中</span>
                                                            </c:if>
                                                            <c:if test="${activity.endTime < nowDate}">
                                                                <span class="status f18 dark">已截止</span>
                                                            </c:if>
                                                        </c:when>
                                                        <c:when test="${activity.checkStatus == 2}">
                                                            <span class="status f18 dark">已拒绝</span>
                                                        </c:when>
                                                    </c:choose>
                                                    <a href="${ctx}/activity/activity/activityDetail.do?actId=${activity.id }"
                                                       class="title f18 text-ellipsis">${activity.title }</a>
                                                </div>
                                                <div>
                                                    <p class="act-price">
                                                        <span style="margin-right: 10px;"> 活动开始时间：<fmt:formatDate
                                                                value="${activity.startTime}"
                                                                pattern="yyyy-MM-dd HH:mm"/></span>
                                                        <span> 报名截止时间：<fmt:formatDate value="${activity.endTime}"
                                                                                      pattern="yyyy-MM-dd HH:mm"/></span>
                                                    </p>
                                                    <p class="act-price">
                                                        <span style="margin-right: 10px;">报名费用：<b
                                                                class="active-red">${activity.newPrice}</b>元/位</span>
                                                        <span class="mr10">限制人数：
															<c:if test="${activity.limitNum == 0}">
                                                                <b class="active-red">不限</b>
                                                            </c:if>
															<c:if test="${activity.limitNum > 0}">
                                                                <b class="active-red">${activity.limitNum }</b>人
                                                            </c:if>
														</span>
                                                        <span style="margin-right: 10px;">报名人数：<b
                                                                class="active-red">${activity.joinNum}</b>人</span>
                                                        <c:if test="${sessionScope.newCurrentUser.id != activity.memberId}">
                                                            <span>发布者：<b class="active-red">${activity.member}</b></span>
                                                        </c:if>
                                                    </p>
                                                    <p class="start-time">活动地点：${activity.area} ${activity.place}</p>
                                                    <p class="act-price">
                                                        发布时间：
                                                        <fmt:formatDate value="${activity.createDate}"
                                                                        pattern="yyyy-MM-dd HH:mm"/>
                                                    </p>
                                                </div>
                                                <div class="opts-btns tb-opts" style="width:475px;">
                                                    <div class="comm-opts">
                                                        <c:if test="${isCommune||isXzgsAdmin}">
                                                            <a href="javascript:batchAddIntegral('${activity.id}', '${activity.memberId}')">
                                                                <i class="iconfont icon-add btn-icon"></i>批量添加积分</a>
                                                        </c:if>
                                                        <a class="qr-btn" href="javascript:txz.openQrDialog({
															title:'扫码二维码可预览分享',
															detailList:[{
																title:'报名二维码',
																url:'${activity.qrCodeMap.detailQrCode}',
																link:'${activity.qrCodeMap.detailQrCodeContent}'
															},{
																title:'签到二维码',
																url:'${activity.qrCodeMap.signQrCode}'
															}<%--,{
																title:'分销二维码',
																url:'${activity.qrCodeMap.disQrCode}',
																link:'${activity.qrCodeMap.disQrCodeContent}'
															}--%>]
														})"><i class="iconfont icon-qrcode btn-icon"></i> 二维码</a>
                                                        <c:if test="${!isTwoLevelChildren}">
                                                            <a href="javascript:txz.expireCheck('${ctx}/activity/activity/publishAct.do?id=${activity.id }')"><i
                                                                    class="iconfont icon-edit btn-icon"></i>编辑</a>
                                                            <a href="javascript:txz.deleteObject('确定要删除吗？','${ctx}/activity/activity/deleteLogic.do?id=${activity.id}','该活动已有人报名，不能删除')">
                                                                <i class="iconfont icon-delete btn-icon"></i> 删除
                                                            </a>
                                                            <c:if test="${activity.checkStatus == 1}">
                                                                <a href="${ctx}/activity/memberAct/memberActList.do?actId=${activity.id }"><i
                                                                        class="iconfont icon-peoplelist btn-icon"></i>报名管理</a>
                                                                <%--                                                            <a href="${ctx}/distribution/relation/targetList/${activity.id }.do"><i
                                                                                                                                    class="iconfont icon-xinxi btn-icon"></i>分销</a>--%>
                                                            </c:if>
                                                            <a href="javascript:txz.expireCheck('', function() { createCircle('${activity.id}') })">
                                                                <i
                                                                        class="iconfont icon-check btn-icon"></i>生成圈子</a>
                                                            <a href="javascript:txz.expireCheck('', function() { createGatherInfo('${activity.id}') })">
                                                                <i
                                                                        class="iconfont icon-check btn-icon"></i>生成信息收集项目</a>
                                                            <a href="${ctx}/notify/template/activity/list.do?targetId=${activity.id}">
                                                                <i class="iconfont icon-mobile1 btn-icon"></i>
                                                                短信推送
                                                            </a>
                                                        </c:if>
                                                        <c:if test="${isTwoLevelChildren}">
                                                            <c:if test="${activity.checkStatus == 1}">
                                                                <a href="${ctx}/activity/memberAct/memberActList.do?actId=${activity.id }"><i
                                                                        class="iconfont icon-peoplelist btn-icon"></i>报名管理</a>
                                                            </c:if>
                                                        </c:if>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </li>
                                </c:forEach>
                            </ul>
                            <div class="f-def-dialog linkDialog">
                                <div class="f-dialog-shadow"></div>
                                <div class="f-dialog-content">
                                    <span class="close-icon"><i class="iconfont icon-close"></i></span>
                                    <div class="dialog-detail">
                                        <p class="f16 gray" id="dialog_title"></p>
                                        <div class="content">
                                            <div>
                                                <div style="width: auto!important;margin: 0px auto;margin-top: 10px;padding-left: 20px;padding-right: 20px;">
                                                    <div id="dialog_content" class="f16"
                                                         style="word-wrap: break-word;margin: 0px auto;line-height: 30px;"></div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="page-content">
                                <div id="page_content" class="page-container"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
</div>

<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript">

    <%--showActive('${input.createStart}', '${input.createEnd}', '#timeType');--%>

    txz.initHeader({
        nav: [{
            name: '活动管理',
            href: '${ctx}/activity/activity/activityList.do'
        }],
        info: '<span class="f14 gray">活动管理是供企业和商会发布活动使用。' +
            '<a href="javascript:openHelpDialog()" class="red ml10"><i class="iconfont icon-mobile"></i>手机端效果</a>\n' +
            '<a href="${ctx}/help/help/list.do?id=a82cd07464134fd0a4374671f3e78f9f" class="red ml10" target="_blank"><i class="iconfont icon-book"></i>帮助教程</a>',
        <c:if test="${!isTwoLevelChildren}">
        btns: [{
            name: '发布活动',
            icon: 'add',
            href: '${ctx}/activity/activity/publishAct.do',
            isCheckExpire: true
        }]
        </c:if>
    });

    function openHelpDialog() {
        txz.openHelpDialog({
            title: '手机效果预览',
            describe: '点击发布活动，' +
                '填写活动详情、报名相关信息、活动标准等内容，即可发布活动，生成二维码，分享给想要邀请的用户，用户扫描二维码即可报名参与活动。',
            detailList: [{
                text: '1/活动详情',
                url: '${ctx}/image/dialog/ac_1.jpg'
            }, {
                text: '2/填写信息',
                url: '${ctx}/image/dialog/ac_2.jpg'
            }, {
                text: '3/报名凭证',
                url: '${ctx}/image/dialog/ac_3.jpg'
            }]
        })
    }

    var form;
    $(function () {
        // 加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });
        layui.use(['element', 'laydate'], function () {
            var laydate = layui.laydate, element = layui.element;
            form = layui.form;
            element.on('tab(type)', function (data) {
                if (data.index == 0) {
                    $('#status').val(0);
                    $('#myForm').submit();
                }
                else if (data.index == 1) {
                    $('#status').val(1);
                    $('#myForm').submit();
                }
            });

            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);
        });
    })
    function createCircle(actId) {
        var content = "确定要生成吗？请选择生成<br/><label for='all1' class='mr10'><input type='radio' id='all1' name='type' value='2' checked='checked' >全部报名人员</label>" +
            "<label for='success'><input type='radio' id='success' name='type' value='1' >已成功报名人员</label>";
        // content = "确定要生成吗？";
        layer.confirm(content, {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            var type = $("[name=type]:checked").val() || '2';
            layer.close(index);
            //loading层
            var loadIndex = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.post("${ctx}/activity/activity/createCircle.do", {
                actId: actId,
                type: type
            }, function (data) {
                layer.close(loadIndex);
                setTimeout(function () {
                    if (data.success) {
                        util.layerMsgSuccess("生成成功")
                    } else {
                        util.layerMsgError("生成失败")
                    }
                });
            })
        });
    }

    function createGatherInfo(actId) {
        var content = "确定要生成吗？请选择生成<br/><label for='all1' class='mr10'><input type='radio' id='all1' name='type' value='2' checked='checked' >全部报名人员</label>" +
            "<label for='success'><input type='radio' id='success' name='type' value='1' >已成功报名人员</label>";
        // content = "确定要生成吗？";
        layer.confirm(content, {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            var type = $("[name=type]:checked").val() || '2';
            layer.close(index);
            //loading层
            var loadIndex = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.post("${ctx}/activity/activity/createGatherInfo.do", {
                actId: actId,
                type: type
            }, function (data) {
                layer.close(loadIndex);
                setTimeout(function () {
                    if (data.success) {
                        util.layerMsgSuccess("生成成功")
                    } else {
                        util.layerMsgError("生成失败")
                    }
                });
            })
        });
    }

    function batchAddIntegral(targetId, partnerId) {
        layer.open({
            type: 2,
            area: ['1250px', '600px'],
            title: '批量添加积分',
            maxmin: true, //开启最大化最小化按钮
            content: '${ctx}/activity/activity/integralMessageView.do?targetId='+targetId+'&partnerId='+partnerId ,
            btn: ['立即添加','关闭'],
            /*yes: function (index, layero) {
                if (behavior != 'add') {
                    return false;
                }
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if (target) {
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                } else {
                    top_iframe = '_parent';//获取当前active的tab的iframe
                }
                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                if (iframeWin.contentWindow.doSubmit()) {
                    setTimeout(function () {
                        top.layer.close(index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug

                    setTimeout(function () {
                        window.location.reload();
                    }, 200);
                }
            },*/
            yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                    top_iframe = '_parent';//获取当前active的tab的iframe

                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                var loadIndex = layer.load(1, {
                    shade: [0.1, '#fff'] //0.1透明度的白色背景
                });

                if (iframeWin.contentWindow.submitQuartz()) {
                    layer.close(loadIndex);
                    setTimeout(function () {
                        top.layer.close(index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug
/*
                    setTimeout(function () {
                        window.location.reload();
                    }, 200);*/
                } else {
                    layer.close(loadIndex);
                    return false;
                }
            },
            cancel: function (index) {
            }
        });
    }
</script>
</body>
</html>